{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a3df90b1",
   "metadata": {},
   "source": [
    "## zhou二：week08\n",
    "本周内容：\n",
    "> 0. 代码的注释\n",
    "> 1. 用户的输入\n",
    "> 2. 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec902ae6",
   "metadata": {},
   "source": [
    "### 0.代码的注释\n",
    "> 1. 一般写在代码块的最上边，或者每一行代码的最后，用于代码思路的记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "42f4764a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Author:Zhichao"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "183b973c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "三个引号注释代码块内容，不运行\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)\n",
    "'''\n",
    "print(\"三个引号注释代码块内容，不运行\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6ba47d0",
   "metadata": {},
   "source": [
    "### 1.用户输入\n",
    "> 1. input( )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "000f7048",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "个人账号：kelay\n",
      "密码：1462\n"
     ]
    }
   ],
   "source": [
    "#用户登录系统\n",
    "username = input(\"个人账号：\")\n",
    "password = input(\"密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b0a64b9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "kelay\n",
      "1462\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b32f38ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:admin\n",
      "密码:123456\n",
      "欢迎admin登录！\n"
     ]
    }
   ],
   "source": [
    "#登录系统 迭代一：增加了判断功能\n",
    "#假设我们数据库有用户信息：账号：admin,密码：123456\n",
    "user1 = \"admin\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "#情景一：输入信息准确，登陆成功\n",
    "if user1 == username and password1 == password:\n",
    "    print(\"欢迎\"+user1+\"登录！\")\n",
    "else:print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "1bbc5735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:ue\n",
      "密码:77\n",
      "账号不存在或密码不正确！\n",
      "您还有2次尝试的机会\n",
      "账号:wk\n",
      "密码:88\n",
      "账号不存在或密码不正确！\n",
      "您还有1次尝试的机会\n",
      "账号:wvj\n",
      "密码:368\n",
      "三次输入失败，请1小时后再来尝试\n"
     ]
    }
   ],
   "source": [
    "#登录系统 迭代一：增加了判断功能\n",
    "#假设我们数据库有用户信息：账号：admin,密码：123456\n",
    "user1 = \"admin\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):# i 是一个int\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "#情景一：输入信息准确，登陆成功\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登录！\")\n",
    "        break # 终止循环\n",
    "#情景二：账号不存在或密码不正确\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败，请1小时后再来尝试\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！\")\n",
    "            print(\"您还有\"+str(i-1)+\"次尝试的机会\") # str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec50ae36",
   "metadata": {},
   "source": [
    "### 2.格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4aab2d7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名:Irving\n",
      "年龄:29\n",
      "工作:basketball\n",
      "收入:600w\n",
      "地区:Newyork\n",
      "——INFOIrving——\n",
      "年龄:29\n",
      "工作:basketball\n",
      "收入:600w\n",
      "地区:Newyork\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统\n",
    "name = input(\"姓名:\")\n",
    "age = input(\"年龄:\")\n",
    "job = input(\"工作:\")\n",
    "salary = input(\"收入:\")\n",
    "reg = input(\"地区:\")\n",
    "\n",
    "info = '''——INFO'''+ name +'''——'''+'''\n",
    "年龄:'''+age+'''\n",
    "工作:'''+job+'''\n",
    "收入:'''+salary+'''\n",
    "地区:'''+reg\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "db5cb99d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名: Irving\n",
      "年龄: 29\n",
      "工作: basketball\n",
      "收入: 600w\n",
      "地区: Newyork\n",
      "————INFO OF Irving————\n",
      "年龄: 29\n",
      "工作: basketball\n",
      "收入: 600w\n",
      "地区: Newyork\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统 方法二：占位符 %s str,依次有序输入\n",
    "name = input(\"姓名: \")\n",
    "age = input(\"年龄: \")\n",
    "job = input(\"工作: \")\n",
    "salary = input(\"收入: \")\n",
    "reg = input(\"地区: \")\n",
    "\n",
    "info = '''————INFO OF %s————\n",
    "年龄: %s\n",
    "工作: %s\n",
    "收入: %s\n",
    "地区: %s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8c75e6b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名: Irving\n",
      "年龄: 29\n",
      "工作: basketball\n",
      "收入: 600w\n",
      "地区: newyork\n",
      "————INFO OF ()姓名————\n",
      "姓名: Irving\n",
      "年龄: 29\n",
      "工作: basketball\n",
      "收入: 600w\n",
      "地区: newyork\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统 方法三：format()格式化输出函数,参数传递，不需要考虑位置\n",
    "name = input(\"姓名: \")\n",
    "age = int(input(\"年龄: \")) #强制将str转换成int\n",
    "job = input(\"工作: \")\n",
    "salary = input(\"收入: \")\n",
    "reg = input(\"地区: \")\n",
    "\n",
    "info = '''————INFO OF ()姓名————\n",
    "姓名: {姓名}\n",
    "年龄: {年龄}\n",
    "工作: {工作}\n",
    "收入: {收入}\n",
    "地区: {地区}'''.format(年龄 = age,姓名 = name,工作 = job,收入 = salary,地区 = reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e830c296",
   "metadata": {},
   "source": [
    "##课后作业：第二章P93前所有项目练习（下周讲) 购物车项目：A. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。 B. 让用户输入商品编号进行商品的购买。 C. 用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。 D. 用户可以随时退出购买，退出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e89740eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "支付宝余额:100\n",
      "商品列表:111;222;333\n",
      "商品编号:333\n"
     ]
    }
   ],
   "source": [
    "#购物车项目：\n",
    "balance = input(\"支付宝余额:\")\n",
    "print(\"商品列表:111;222;333\")\n",
    "number = input(\"商品编号:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf184364",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
